import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:health/components/home/home.dart';
import 'package:health/icons/flutter_icons.dart';
import 'package:health/utils/colors.dart';
import 'package:health/utils/styles.dart';
import 'package:health/utils/tools.dart';

import 'home_logic.dart';

///
/// final _user = Rx<User?>(null);
///
class HomePage extends GetView<HomeLogic> {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeLogic>(
      builder: (_) {
        return Scaffold(
          body: createPageView(context),
          bottomNavigationBar: Obx(() => BottomNavigationBar(
                backgroundColor: Colors.white,
                type: BottomNavigationBarType.fixed,
                iconSize: 20,
                selectedLabelStyle: StylesUtils.customTextStyle(color: ColorsUtils.color096d),
                unselectedLabelStyle: StylesUtils.customTextStyle(color: ColorsUtils.colorAaaa),
                elevation: 0,
                items: [
                  BottomNavigationBarItem(
                      icon: ToolsUtils.getAssetImageSvg('home', width: 20, height: 19),
                      activeIcon: ToolsUtils.getAssetImageSvg('home_active', width: 20, height: 19),
                      label: '首页'),
                  BottomNavigationBarItem(
                      icon: ToolsUtils.getAssetImageSvg('service', width: 20, height: 19),
                      activeIcon:
                          ToolsUtils.getAssetImageSvg('service_active', width: 20, height: 19),
                      label: '服务'),
                  BottomNavigationBarItem(
                      icon: ToolsUtils.getAssetImageSvg('discover', width: 20, height: 19),
                      activeIcon:
                          ToolsUtils.getAssetImageSvg('discover_active', width: 20, height: 19),
                      label: '发现'),
                  BottomNavigationBarItem(
                      icon: ToolsUtils.getAssetImageSvg('mall', width: 20, height: 19),
                      activeIcon: ToolsUtils.getAssetImageSvg('mall_active', width: 20, height: 19),
                      label: '商城'),
                  BottomNavigationBarItem(
                      icon: Icon(
                        AntdIcons.user,
                        size: 20,
                        color: ColorsUtils.parseColorFromHexString('#aaaaaa'),
                      ),
                      activeIcon: Icon(
                        AntdIcons.user,
                        size: 20,
                        color: ColorsUtils.parseColorFromHexString('#096dd9'),
                      ),
                      label: '我的'),
                ],
                currentIndex: controller.currentIndex.value,
                onTap: (int index) {
                  controller.currentIndex.value = index;
                  controller.pageController.animateToPage(index,
                      duration: const Duration(milliseconds: 500), curve: Curves.linear);
                },
              )),
        );
      },
      init: controller,
    );
  }

  PageView createPageView(BuildContext context) {
    return PageView(
      physics: const NeverScrollableScrollPhysics(),
      scrollBehavior: const ScrollBehavior(),
      controller: controller.pageController,
      children: [IndexPage(), ServicePage(), DiscoverPage(), MallPage(), MinePage()],
    );
  }
}
